/*
 * HeatMeterInfoBO.java 
 * 
 * Copyright 2009 Wangfeng Beijing Inc. 
 * All rights reserved. 
 * 
 * Created on 2012-07-06
 */

package com.bjtech.domain.query;

import java.util.Date;
import com.bjtech.web.util.SelectBean;
import org.ssi.web.util.QuerySpecTpl;

/**
 * 功能概述:热量表信息管理 <br>
 * 
 * @author 王峰
 */

public class HeatMeterInfoQuerySpec extends SelectBean {
	/* */
	private Long id;
	/* */
	private Long build_id;
	/* */
	private String meter_num;
	/* */
	private Long cal_type;
	/* */
	private String meta_type;
	/* */
	private Float pipe_dia;
	/* */
	private Float meta_dia;
	/* */
	private String prod_fac;
	/* */
	private Date prod_date;
	private Date b_prod_date;
	private Date e_prod_date;
	/* */
	private Date install_date;
	private Date b_install_date;
	private Date e_install_date;
	/* */
	private Long install_pos;
	/* */
	private Long install_env;
	/* */
	private String install_pic;
	/* */
	private String demo;
	
	private Long proj_id;
	
	private Long p_index;

	@Override
	public void queryParamString() {
		StringBuilder fromPart = new StringBuilder(" where 1=1");

		if (this.isAll != null && this.isAll.intValue() != 1) {
			if (QuerySpecTpl.isValid(id)) {
				fromPart.append(" and a.id = ");
				fromPart.append(id);
			}

			if (QuerySpecTpl.isValid(build_id)) {
				fromPart.append(" and a.build_id = ");
				fromPart.append(build_id);
			}

			if (QuerySpecTpl.isValid(meter_num)) {
				fromPart.append(" and a.meter_num like ");
				fromPart.append(" CONCAT('%','");
				fromPart.append(meter_num);
				fromPart.append("','%')");
			}

			if (QuerySpecTpl.isValid(cal_type)) {
				fromPart.append(" and a.cal_type = ");
				fromPart.append(cal_type);
			}

			if (QuerySpecTpl.isValid(meta_type)) {
				fromPart.append(" and a.meta_type like ");
				fromPart.append(" CONCAT('%','");
				fromPart.append(meta_type);
				fromPart.append("','%')");
			}

			if (QuerySpecTpl.isValid(pipe_dia)) {
				fromPart.append(" and a.pipe_dia = ");
				fromPart.append(pipe_dia);
			}

			if (QuerySpecTpl.isValid(meta_dia)) {
				fromPart.append(" and a.meta_dia = ");
				fromPart.append(meta_dia);
			}

			if (QuerySpecTpl.isValid(prod_fac)) {
				fromPart.append(" and a.prod_fac like ");
				fromPart.append(" CONCAT('%','");
				fromPart.append(prod_fac);
				fromPart.append("','%')");
			}

			if (QuerySpecTpl.isValid(prod_date)) {
				fromPart
						.append(" and str_to_date(a.prod_date,'%Y-%m-%d')=str_to_date(CONCAT(''',");
				fromPart.append(prod_date);
				fromPart.append(",'''),'%Y-%m-%d')");
			}
			if (QuerySpecTpl.isValid(b_prod_date)) {
				fromPart
						.append(" and str_to_date(a.prod_date,'%Y-%m-%d')>=str_to_date(CONCAT(''',");
				fromPart.append(b_prod_date);
				fromPart.append(",'''),'%Y-%m-%d')");
			}
			if (QuerySpecTpl.isValid(e_prod_date)) {
				fromPart
						.append(" and str_to_date(a.prod_date,'%Y-%m-%d')<=str_to_date(CONCAT(''',");
				fromPart.append(e_prod_date);
				fromPart.append(",'''),'%Y-%m-%d')");
			}

			if (QuerySpecTpl.isValid(install_date)) {
				fromPart
						.append(" and str_to_date(a.install_date,'%Y-%m-%d')=str_to_date(CONCAT(''',");
				fromPart.append(install_date);
				fromPart.append(",'''),'%Y-%m-%d')");
			}
			if (QuerySpecTpl.isValid(b_install_date)) {
				fromPart
						.append(" and str_to_date(a.install_date,'%Y-%m-%d')>=str_to_date(CONCAT(''',");
				fromPart.append(b_install_date);
				fromPart.append(",'''),'%Y-%m-%d')");
			}
			if (QuerySpecTpl.isValid(e_install_date)) {
				fromPart
						.append(" and str_to_date(a.install_date,'%Y-%m-%d')<=str_to_date(CONCAT(''',");
				fromPart.append(e_install_date);
				fromPart.append(",'''),'%Y-%m-%d')");
			}

			if (QuerySpecTpl.isValid(install_pos)) {
				fromPart.append(" and a.install_pos = ");
				fromPart.append(install_pos);
			}

			if (QuerySpecTpl.isValid(install_env)) {
				fromPart.append(" and a.install_env = ");
				fromPart.append(install_env);
			}

			if (QuerySpecTpl.isValid(install_pic)) {
				fromPart.append(" and a.install_pic like ");
				fromPart.append(" CONCAT('%','");
				fromPart.append(install_pic);
				fromPart.append("','%')");
			}

			if (QuerySpecTpl.isValid(demo)) {
				fromPart.append(" and a.demo like ");
				fromPart.append(" CONCAT('%','");
				fromPart.append(demo);
				fromPart.append("','%')");
			}
			
			if (QuerySpecTpl.isValid(proj_id)) {
				fromPart.append(" and a.area_id in (select id from BASE_SHARE_AREA_INFO where proj_id= ");
				fromPart.append(proj_id);
				fromPart.append(")");
			}
			
			if (QuerySpecTpl.isValid(p_index)) {
				fromPart.append(" and a.area_id in (select id from BASE_SHARE_AREA_INFO where proj_id in (select id from BASE_PROJECT_INFO where p_index=");
				fromPart.append(p_index);
				fromPart.append("))");
			}

			if (QuerySpecTpl.isValid(this.direction)
					&& QuerySpecTpl.isValid(this.sort)) {
				fromPart.append(" order by ");
				fromPart.append(this.sort);
				fromPart.append(" ");
				fromPart.append(this.direction);
			} else {
				fromPart.append(" order by ");
				fromPart.append("id");
				fromPart.append(" ");
				fromPart.append("asc");

			}
		}
		super.setQueryString(fromPart.toString());
	}

	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getBuild_id() {
		return this.build_id;
	}

	public void setBuild_id(Long build_id) {
		this.build_id = build_id;
	}

	public String getMeter_num() {
		return this.meter_num;
	}

	public void setMeter_num(String meter_num) {
		this.meter_num = meter_num;
	}

	public Long getCal_type() {
		return this.cal_type;
	}

	public void setCal_type(Long cal_type) {
		this.cal_type = cal_type;
	}

	public String getMeta_type() {
		return this.meta_type;
	}

	public void setMeta_type(String meta_type) {
		this.meta_type = meta_type;
	}

	public Float getPipe_dia() {
		return this.pipe_dia;
	}

	public void setPipe_dia(Float pipe_dia) {
		this.pipe_dia = pipe_dia;
	}

	public Float getMeta_dia() {
		return this.meta_dia;
	}

	public void setMeta_dia(Float meta_dia) {
		this.meta_dia = meta_dia;
	}

	public String getProd_fac() {
		return this.prod_fac;
	}

	public void setProd_fac(String prod_fac) {
		this.prod_fac = prod_fac;
	}

	public Date getProd_date() {
		return this.prod_date;
	}

	public void setProd_date(Date prod_date) {
		this.prod_date = prod_date;
	}

	public Date getB_prod_date() {
		return this.b_prod_date;
	}

	public void setB_prod_date(Date b_prod_date) {
		this.b_prod_date = b_prod_date;
	}

	public Date getE_prod_date() {
		return this.e_prod_date;
	}

	public void setE_prod_date(Date e_prod_date) {
		this.e_prod_date = e_prod_date;
	}

	public Date getInstall_date() {
		return this.install_date;
	}

	public void setInstall_date(Date install_date) {
		this.install_date = install_date;
	}

	public Date getB_install_date() {
		return this.b_install_date;
	}

	public void setB_install_date(Date b_install_date) {
		this.b_install_date = b_install_date;
	}

	public Date getE_install_date() {
		return this.e_install_date;
	}

	public void setE_install_date(Date e_install_date) {
		this.e_install_date = e_install_date;
	}

	public Long getInstall_pos() {
		return this.install_pos;
	}

	public void setInstall_pos(Long install_pos) {
		this.install_pos = install_pos;
	}

	public Long getInstall_env() {
		return this.install_env;
	}

	public void setInstall_env(Long install_env) {
		this.install_env = install_env;
	}

	public String getInstall_pic() {
		return this.install_pic;
	}

	public void setInstall_pic(String install_pic) {
		this.install_pic = install_pic;
	}

	public String getDemo() {
		return this.demo;
	}

	public void setDemo(String demo) {
		this.demo = demo;
	}

	public Long getProj_id() {
		return proj_id;
	}

	public void setProj_id(Long projId) {
		proj_id = projId;
	}

	public Long getP_index() {
		return p_index;
	}

	public void setP_index(Long pIndex) {
		p_index = pIndex;
	}
}
